<?php

namespace app\admin\model\prison;

use think\Model;


class DetentionPrison extends Model
{

    

    

    // 表名
    protected $name = 'detention_prison';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'address_verify_text',
        'communication_verify_text',
        'mail_type_text',
        'mail_method_text',
        'status_text'
    ];
    

    
    public function getTypeList()
    {
        return ['0' => __('Type 0'), '1' => __('Type 1')];
    }

    public function getAddressVerifyList()
    {
        return ['0' => __('Address_verify 0'), '1' => __('Address_verify 1')];
    }

    public function getCommunicationVerifyList()
    {
        return ['0' => __('Communication_verify 0'), '1' => __('Communication_verify 1')];
    }

    public function getMailTypeList()
    {
        return ['0' => __('Mail_type 0'), '1' => __('Mail_type 1'), '-1' => __('Mail_type -1')];
    }

    public function getMailMethodList()
    {
        return ['0' => __('Mail_method 0'), '1' => __('Mail_method 1'), '-1' => __('Mail_method -1')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAddressVerifyTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['address_verify']) ? $data['address_verify'] : '');
        $list = $this->getAddressVerifyList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCommunicationVerifyTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['communication_verify']) ? $data['communication_verify'] : '');
        $list = $this->getCommunicationVerifyList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getMailTypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['mail_type'] ?? '');
        $valueArr = explode(',', $value);
        $list = $this->getMailTypeList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function getMailMethodTextAttr($value, $data)
    {
        $value = $value ?: ($data['mail_method'] ?? '');
        $valueArr = explode(',', $value);
        $list = $this->getMailMethodList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setMailTypeAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    protected function setMailMethodAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    public function province()
    {
        return $this->belongsTo('app\admin\model\shopro\data\Area', 'province_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function city()
    {
        return $this->belongsTo('app\admin\model\shopro\data\Area', 'city_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function area()
    {
        return $this->belongsTo('app\admin\model\shopro\data\Area', 'area_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}
